convert Mapbar track to Format class (#841)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 29 Jan 2022 21:45:30 +0000 (14:45 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 21:45:30 +0000 (14:45 -0700)
* convert mapbar_track to Format class.

* const member funcs

CMakeLists.txt
GPSBabel.pro
mapbar_track.cc
mapbar_track.h [new file with mode: 0644]
vecs.h

index 616d385e3ceb5d055fee3c65c76917bd400d1196..07d53e048395ab8abf2f99e5a3546c387470988d 100644 (file)
@@ -249,6 +249,7 @@ set(HEADERS
   legacyformat.h
   lowranceusr.h
   magellan.h
+  mapbar_track.h
   mapfactor.h
   mynav.h
   navilink.h
index 6a1ada81e1555af562edc7f3e11a0ef8e3d15bdb..975b017480009b578ccf27d0eef8836eb6bf49a5 100644 (file)
@@ -236,6 +236,7 @@ HEADERS =  \
   legacyformat.h \
   lowranceusr.h \
   magellan.h \
+  mapbar_track.h \
   mapfactor.h \
   mynav.h \
   navilink.h \
index 002c8867c328633c40924621eb5f71eeaa073511..25df919da2b4a052758dc99246507586a575e6d0 100644 (file)
 
  */
 
-#include <cstdio>               // for SEEK_CUR
+#include "mapbar_track.h"
 
 #include <QChar>                // for QChar
 #include <QDate>                // for QDate
 #include <QString>              // for QString
 #include <QTime>                // for QTime
-#include <QVector>              // for QVector
 
-#include "defs.h"
-#include "gbfile.h"             // for gbfgetint16, gbfgetint32, gbfseek, gbfclose, gbfopen, gbfile
+#include <cstdio>               // for SEEK_CUR
+
+#include "defs.h"               // for fatal, Waypoint, track_add_head, track_add_wpt, route_head
+#include "gbfile.h"             // for gbfgetint16, gbfgetint32, gbfseek, gbfclose, gbfopen
 #include "src/core/datetime.h"  // for DateTime
 
 
 #define MYNAME "mapbar_track"
 
-static gbfile* fin;
-
-static
-QVector<arglist_t> mapbar_track_args = {
-};
-
 /*******************************************************************************
 * %%%        global callbacks called by gpsbabel main process              %%% *
 *******************************************************************************/
 
-static void
-mapbar_track_rd_init(const QString& fname)
+void
+MapbarTrackFormat::rd_init(const QString& fname)
 {
   fin = gbfopen(fname, "r", MYNAME);
 }
 
-static void
-mapbar_track_rd_deinit()
+void
+MapbarTrackFormat::rd_deinit()
 {
   gbfclose(fin);
 }
 
-static gpsbabel::DateTime
-read_datetime()
+gpsbabel::DateTime
+MapbarTrackFormat::read_datetime() const
 {
   int hour = gbfgetint16(fin);
   int min = gbfgetint16(fin);
@@ -71,9 +66,8 @@ read_datetime()
   return t;
 }
 
-static const double DIV_RATE  = 100000.0f;
-static Waypoint*
-read_waypoint()
+Waypoint*
+MapbarTrackFormat::read_waypoint() const
 {
   int longitude = gbfgetint32(fin);
   int latitude = gbfgetint32(fin);
@@ -86,8 +80,8 @@ read_waypoint()
   return ret;
 }
 
-static void
-mapbar_track_read()
+void
+MapbarTrackFormat::read()
 {
   auto* track = new route_head;
   track_add_head(track);
@@ -134,22 +128,3 @@ mapbar_track_read()
     end_flag = gbfgetint32(fin);
   }
 }
-
-// capabilities below means: we can only read trackpoints.
-
-ff_vecs_t mapbar_track_vecs = {
-  ff_type_file,
-  { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none },
-  mapbar_track_rd_init,
-  nullptr,
-  mapbar_track_rd_deinit,
-  nullptr,
-  mapbar_track_read,
-  nullptr,
-  nullptr,
-  &mapbar_track_args,
-  CET_CHARSET_UTF8, 0
-  /* not fixed, can be changed through command line parameter */
-  , NULL_POS_OPS,
-  nullptr
-};
diff --git a/mapbar_track.h b/mapbar_track.h
new file mode 100644 (file)
index 0000000..b522a55
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+    China mapbar navigation track reader for sonim xp3300
+       it's maybe can used in other demo devices of mapbar navigation
+
+    Copyright (C) 2013 xiao jian cheng, azuresky.xjc@gmail.com
+    Copyright (C) 2001-2013 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef MAPBAR_TRACK_H_INCLUDED_
+#define MAPBAR_TRACK_H_INCLUDED_
+
+#include <QString>              // for QString
+#include <QVector>              // for QVector
+
+#include "defs.h"               // for ff_cap, arglist_t, ff_cap_none, CET_CHARSET_UTF8, Waypoint, ff_cap_read, ff_type, ff_type_file
+#include "format.h"             // for Format
+#include "gbfile.h"             // for gbfile
+#include "src/core/datetime.h"  // for DateTime
+
+
+class MapbarTrackFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &mapbar_track_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /*         waypoints,                tracks,      routes */
+    return { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none };
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_UTF8;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void rd_deinit() override;
+
+private:
+  /* Constants */
+
+  static constexpr double DIV_RATE  = 100000.0f;
+
+  /* Member Functions */
+
+  gpsbabel::DateTime read_datetime() const;
+  Waypoint* read_waypoint() const;
+
+  /* Data Members */
+
+  gbfile* fin{};
+
+  QVector<arglist_t> mapbar_track_args = {
+  };
+};
+#endif // MAPBAR_TRACK_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index e82dc6b7f288e9e1186efd345fd12e5e1c2e0df1..5ef98f33392d1adb60662907a05020082eed4243 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -42,6 +42,7 @@
 #include "kml.h"
 #include "legacyformat.h"
 #include "lowranceusr.h"
+#include "mapbar_track.h"
 #include "mapfactor.h"
 #include "mynav.h"
 #include "nmea.h"
@@ -125,7 +126,6 @@ extern ff_vecs_t mmo_vecs;
 extern ff_vecs_t v900_vecs;
 extern ff_vecs_t enigma_vecs;
 extern ff_vecs_t format_garmin_xt_vecs;
-extern ff_vecs_t mapbar_track_vecs;
 extern ff_vecs_t f90g_track_vecs;
 #endif // MAXIMAL_ENABLED
 
@@ -319,7 +319,7 @@ private:
   SubripFormat subrip_fmt;
   LegacyFormat format_garmin_xt_fmt {format_garmin_xt_vecs};
   GarminFitFormat format_fit_fmt;
-  LegacyFormat mapbar_track_fmt {mapbar_track_vecs};
+  MapbarTrackFormat mapbar_track_fmt;
   LegacyFormat f90g_track_fmt {f90g_track_vecs};
   MapfactorFormat mapfactor_fmt;
   EnergymproFormat energympro_fmt;